package com.rt.schedulenew.web;

import com.rt.schedulebase.dto.*;
import com.rt.schedulebase.entity.ExamApply;
import com.rt.schedulenew.api.IDictScheduleApmService;
import com.rt.schedulenew.api.IExamApplyPatientService;
import com.rt.schedulenew.api.IExamApplyService;
import com.rt.schedulenew.api.IScheduleSignService;
import com.rt.schedulenew.service.impl.ConfigServiceImpl;
import com.rt.schedulenew.utils.annotation.ServiceLimit;
import com.rt.schedulenew.utils.base.CommonUtil;
import com.rt.schedulenew.utils.base.ConstantsUtil;
import com.rt.schedulenew.utils.base.ShiroUtil;
import com.rt.schedulenew.utils.checkparam.config.Check;
import com.rt.schedulenew.utils.checkparam.config.CheckOne;
import com.rt.schedulenew.utils.global.BusinessException;
import com.rt.schedulenew.utils.global.JsonResult;
import com.rt.schedulenew.utils.global.JsonResultUtil;
import com.rt.schedulenew.utils.global.LocalLock;
import com.rt.schedulenew.utils.util.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.text.ParseException;
import java.util.*;

/**
 * 预约操作相关接口
 */
@RestController
@RequestMapping({"/schedule"})
public class ScheduleController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IExamApplyPatientService examApplyPatientService;
    @Autowired
    private IExamApplyService examApplyService;
    @Autowired
    private IScheduleSignService scheduleSignService;
    @Autowired
    private ConfigServiceImpl configServiceImpl;
    @Autowired
    private IDictScheduleApmService dictScheduleApmService;

    @ApiOperation(value = "患者列表", httpMethod = "POST", notes = "申请单患者列表")
    @PostMapping({"/patient/list"})
    public JsonResult getPatientList(@RequestBody ExamApplyDto dto) {
        JsonResult jsonResult = examApplyPatientService.getPatientList(dto, false);
        return jsonResult;
    }

    @ApiOperation(value = "患者详情列表", httpMethod = "POST", notes = "申请单患者详情列表")
    @PostMapping({"/patient/infoList"})
    public JsonResult getPatientInfoList(@RequestBody ExamApplyDto dto) {
        return examApplyPatientService.getPatientList(dto, true);
    }

    @ApiOperation(value = "患者详情", httpMethod = "POST", notes = "患者详情")
    @RequestMapping({"/patient/info"})
    public JsonResult getPatientInfo(@RequestBody ExamApplyPatientDto dto) {
        DictUsersDto currentUser = (DictUsersDto) ShiroUtil.getCurrentUser();
        if (Objects.nonNull(currentUser) && "patient".equals(currentUser.getRoleId())
                && !dto.getCommonCard().equals(currentUser.getStaffType())) {
            return JsonResultUtil.failure("登录病人和查询病人卡号不一致!");
        }

        JsonResult jsonResult = examApplyPatientService.getPatientInfo(dto);
        return jsonResult;
    }

    @ApiOperation(value = "申请单详情", httpMethod = "POST", notes = "患者申请单详细列表")
    @PostMapping({"/patient/applyList"})
    public JsonResult getPatientApplyList(@RequestBody ExamApplyDto dto) {
        DictUsersDto currentUser = (DictUsersDto) ShiroUtil.getCurrentUser();
        if (Objects.nonNull(currentUser)
                && "patient".equals(currentUser.getRoleId())
                && !dto.getSickId().equals(currentUser.getStaffType())) {
            return JsonResultUtil.failure("登录病人和查询病人卡号不一致!");
        }

        JsonResult jsonResult = examApplyPatientService.getPatientApplyList(dto);
        if ("0".equals(jsonResult.getStatus())) {
            List<ExamApplyDto> result = (List<ExamApplyDto>) jsonResult.getResult();
            if (!CollectionUtils.isEmpty(result)) {
                result.forEach(vo -> {
                    List<ExamApplyItemDto> items = vo.getItems();
                    items.forEach(item -> {
                        if (StringUtils.isNotBlank(item.getNotice())) {
                            Document document = Jsoup.parse(item.getNotice());
                            Elements str1 = document.getElementsByTag("text");
                            String text = str1.text();
                            if (StringUtils.isNotBlank(text) && !text.equals("无")) {
                                item.setText(text);
                            }
                            Elements str2 = document.getElementsByTag("taboo");
                            String taboo = str2.text();
                            if (StringUtils.isNotBlank(taboo) && !taboo.isEmpty()) {
                                item.setTaboo(taboo);
                            }
                        }
                    });
                    vo.setItems(items);
                });
            }
            jsonResult.setResult(result);
        }
        return jsonResult;
    }

    @ApiOperation(value = "申请日期", httpMethod = "POST", notes = "可预约日期列表")
    @PostMapping({"/date/list"})
//    @Check({"applyNo"})
    public JsonResult getDateList(@RequestBody ExamApplyDto dto) {
        if (StringUtils.isEmpty(dto.getApplyNo())) {
            return JsonResultUtil.failure("申请编号为空，请选择患者或检查数据！");
        }
        return examApplyService.getDateList(dto);
    }


    /**
     * @param dto
     * @return
     * @description 根据预约条件查询可以预约的时段列表
     * @author ryan.li
     * @date 2022/10/21 11:25
     */
    @PostMapping({"/apm/list"})
    public JsonResult getApmList(@RequestBody ExamApplyDto dto) {
        return examApplyService.getApmList(dto);
    }

    /**
     * 锁定预约时段
     *
     * @param dto
     * @return
     */
    @PostMapping({"/apm/set"})
    @LocalLock(key = "localLock:arg[0]")
    @ServiceLimit(limitType = ServiceLimit.LimitType.URL)
    public JsonResult setApm(@RequestBody ExamApplyDto dto) {
        return examApplyService.setApm(dto);
    }

    /***
     * 确认申请预约时间
     * @param dto
     * @return
     */
    @ApiOperation(value = "确认申请预约时间", httpMethod = "POST", notes = "申请预约时间确认")
    @PostMapping({"/apm/confirm"})
    @LocalLock(key = "localLock:arg[0]")
    public JsonResult confirmApm(@RequestBody ExamApplyDto dto) {
        JsonResult jsonResult = null;
        try {
            jsonResult = examApplyService.confirmApm(dto);
            if (jsonResult.getStatus().equals("0")) {
                ExamApplyDto examApplyDto = new ExamApplyDto();
                List<String> applyNos = CommonUtil.mergeNo2ApplyNos(dto.getMergeNo());
                examApplyDto.setApplyNos(applyNos);
                ExamApplyDto applyResult = (ExamApplyDto) jsonResult.getResult();
                String actType = applyResult.getActType();
                examApplyDto.setActType(actType);
                examApplyDto.setExamClass(applyResult.getExamClass());
                examApplyDto.setScheduledId(applyResult.getScheduledId());
                examApplyDto.setMergeNo(applyResult.getMergeNo());
                examApplyDto.setApplyNo(dto.getApplyNo());
                examApplyDto.setTerminalType(applyResult.getTerminalType());

                boolean scheduleSync = configServiceImpl.isScheduleSync(examApplyDto, actType, ConstantsUtil.ScheduleStatus.EIGHT.getStatus());
                if (!scheduleSync) {
                    return JsonResultUtil.failure("预约失败,请联系工作人员");
                }
//            boolean isSucc = configServiceImpl.isScheduleSync(examApplyDto, actType, ConstantsUtil.ScheduleStatus.EIGHT.getStatus());
//            if (!isSucc) {
//                return JsonResultUtil.failure("预约失败,请联系工作人员");
//            }
            }
        } catch (Exception e) {
            log.error("确认预约失败:", e);
            if (Objects.nonNull(e) && StringUtils.isNotBlank(e.getMessage()) && e.getMessage().contains("PACS")) {
                return JsonResultUtil.failure(e.getMessage());
            }
            if (e instanceof BusinessException) {
                return JsonResultUtil.failure(e.getMessage());
            }
            return JsonResultUtil.failure(e.getMessage());
        }
        return jsonResult;
    }

    @ApiOperation(value = "取消预约/取消锁定", httpMethod = "POST", notes = "申请单取消预约")
    @PostMapping({"/apm/del"})
    @LocalLock(key = "localLock:arg[0]")
    public JsonResult delApm(@RequestBody ExamApplyDto dto) {
        JsonResult jsonResult = examApplyService.delApm(dto);
        if (jsonResult.getStatus().equals("0")) {
            ExamApplyDto ea = (ExamApplyDto) jsonResult.getResult();
            if (!"01".equals(ea.getScheduleStatus())) {
                ExamApplyDto examApplyDto = new ExamApplyDto();
                List<String> applyNos = CommonUtil.mergeNo2ApplyNos(dto.getMergeNo());
                examApplyDto.setApplyNos(applyNos);
                String actType = ConstantsUtil.ActType.CANCEL.getType();
                examApplyDto.setActType(actType);
                ExamApplyDto applyResult = (ExamApplyDto) jsonResult.getResult();
                examApplyDto.setExamClass(applyResult.getExamClass());
                examApplyDto.setScheduledId(applyResult.getScheduledId());
                examApplyDto.setMergeNo(applyResult.getMergeNo());
                examApplyDto.setApplyNo(dto.getApplyNo());
                examApplyDto.setTerminalType(applyResult.getTerminalType());
                examApplyDto.setScheduleDate(applyResult.getScheduleDate());
                examApplyDto.setName(applyResult.getName());
                examApplyDto.setSex(applyResult.getSex());
                examApplyDto.setAge(applyResult.getAge());
                examApplyDto.setScheduleApm(applyResult.getScheduleApm());
                examApplyDto.setScheduleHospitalName(applyResult.getScheduleHospitalName());
                examApplyDto.setPerformDeptName(applyResult.getPerformDeptName());
                String itemNameStr = "";
                for (ExamApplyItemDto item : applyResult.getItems()) {
                    itemNameStr = itemNameStr + item.getItemName() + ";";
                }
                examApplyDto.setItemNameStr(itemNameStr);
                configServiceImpl.isScheduleSync(examApplyDto, actType, ConstantsUtil.ScheduleStatus.NINE.getStatus());
            }
        }
        return jsonResult;
    }

    @ApiOperation(value = "合单信息", httpMethod = "POST", notes = "申请合单信息")
    @PostMapping({"/patient/getExamApplyInfo"})
    public JsonResult getExamApplyInfo(@RequestBody ExamApplyDto dto) {
        JsonResult jsonResult = examApplyPatientService.getExamApplyInfo(dto);
        ExamApplyDto result = (ExamApplyDto) jsonResult.getResult();
        List<ExamItemDto> examItems = result.getExamItems();
        examItems.forEach(item -> {
            if (StringUtils.isNotBlank(item.getNotice())) {
                Document document = Jsoup.parse(item.getNotice());
                Elements str1 = document.getElementsByTag("text");
                String text = str1.text();
                if (StringUtils.isNotBlank(text) && !text.equals("无")) {
                    item.setText(text);
                }
                Elements str2 = document.getElementsByTag("taboo");
                String taboo = str2.text();
                if (StringUtils.isNotBlank(taboo) && taboo.length() > 0) {
                    item.setTaboo(taboo);
                }
            }

            /*String[] strings = item.getNotice().split("</text><taboo>");
            if (strings.length == 2) {
                String text = strings[0];
                text = text.split("<text>")[1];
                if (!text.equals("无")) {
                    item.setText(text);
                }

                String taboo = strings[1];
                taboo = taboo.split("</taboo>")[0];
                item.setTaboo(taboo);
            }*/
        });
        result.setExamItems(examItems);
        jsonResult.setResult(result);
        return jsonResult;
    }

    @ApiOperation(value = "修改预约", httpMethod = "POST", notes = "修改预约时间")
    @PostMapping({"/apm/edit"})
    @LocalLock(key = "localLock:arg[0]")
    public JsonResult editApm(@RequestBody ExamApplyDto dto) {
        JsonResult jsonResult = examApplyService.editApm(dto);
        if (jsonResult.getStatus().equals("0")) {
            ExamApplyDto examApplyDto = new ExamApplyDto();
            List<String> applyNos = CommonUtil.mergeNo2ApplyNos(dto.getMergeNo());
            examApplyDto.setApplyNos(applyNos);
            String actType = ConstantsUtil.ActType.UPDATE.getType();
            examApplyDto.setActType(actType);
            ExamApplyDto applyResult = (ExamApplyDto) jsonResult.getResult();
            examApplyDto.setExamClass(applyResult.getExamClass());
            examApplyDto.setScheduledId(applyResult.getScheduledId());
            examApplyDto.setMergeNo(applyResult.getMergeNo());
            examApplyDto.setApplyNo(dto.getApplyNo());
            examApplyDto.setTerminalType(applyResult.getTerminalType());
            boolean isSucc = configServiceImpl.isScheduleSync(examApplyDto, actType, ConstantsUtil.ScheduleStatus.EIGHT.getStatus());
            if (!isSucc) {
                return JsonResultUtil.failure("预约失败,请联系工作人员");
            }
        }
        return jsonResult;
    }

    /**
     * 报到
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "报到", httpMethod = "POST", notes = "修改为报到状态")
    @PostMapping({"/apm/sign"})
    @LocalLock(key = "localLock:arg[0]")
    public JsonResult signinSchedule(@RequestBody ExamApplyDto dto) {
        JsonResult jsonResult = examApplyService.signinSchedule(dto);
        if (jsonResult.getStatus().equals("0")) {
            ExamApplyDto ea = (ExamApplyDto) jsonResult.getResult();
            if (StringUtils.isBlank(ea.getIsSign())) {
                ExamApplyDto examApplyDto = new ExamApplyDto();
                List<String> applyNos = CommonUtil.mergeNo2ApplyNos(dto.getMergeNo());
                examApplyDto.setApplyNos(applyNos);
                String actType = ConstantsUtil.ActType.SIGN.getType();
                examApplyDto.setActType(actType);
                ExamApplyDto applyResult = (ExamApplyDto) jsonResult.getResult();
                examApplyDto.setExamClass(applyResult.getExamClass());
                examApplyDto.setScheduledId(applyResult.getScheduledId());
                examApplyDto.setMergeNo(applyResult.getMergeNo());
                examApplyDto.setApplyNo(dto.getApplyNo());
                examApplyDto.setTerminalType(applyResult.getTerminalType());
                configServiceImpl.isScheduleSync(examApplyDto, actType, ConstantsUtil.ScheduleStatus.TEN.getStatus());
            }
        }
        return jsonResult;
    }

    @ApiOperation(value = "多条报到", httpMethod = "POST", notes = "多条申请单报到")
    @PostMapping({"/apm/signMulti"})
    @LocalLock(key = "localLock:arg[0]")
    public JsonResult signInScheduledMulti(@RequestBody ExamApplyDto dto) {
        return examApplyService.signInScheduledMulti(dto);
    }

    @PostMapping({"/apm/signItem"})
    @LocalLock(key = "localLock:arg[0]")
    public JsonResult signInScheduledItem(@RequestBody ExamApplyDto dto) {
        return examApplyService.signInScheduledItem(dto);
    }

    @PostMapping({"/apm/noRegular"})
    @LocalLock(key = "localLock:arg[0]")
    public JsonResult noRegularSchedule(@RequestBody ExamApplyDto dto) {
        JsonResult jsonResult = examApplyService.noRegularSchedule(dto);
        if (jsonResult.getStatus().equals("0")) {
            ExamApplyDto examApplyDto = new ExamApplyDto();
            List<String> applyNos = (List<String>) CommonUtil.mergeNo2ApplyNos(dto.getMergeNo());
            examApplyDto.setApplyNos((List) applyNos);
            ExamApplyDto applyResult = (ExamApplyDto) jsonResult.getResult();
            String actType = applyResult.getActType();
            examApplyDto.setActType(actType);
            examApplyDto.setExamClass(applyResult.getExamClass());
            examApplyDto.setScheduledId(applyResult.getScheduledId());
            examApplyDto.setMergeNo(applyResult.getMergeNo());
            examApplyDto.setApplyNo(dto.getApplyNo());
            examApplyDto.setTerminalType(applyResult.getTerminalType());
            boolean isSucc = configServiceImpl.isScheduleSync(examApplyDto, actType, ConstantsUtil.ScheduleStatus.EIGHT.getStatus());
            if (!isSucc) {
                return JsonResultUtil.failure("预约失败,请联系工作人员");
            }
            if (applyResult.getIsGetQueueNoFirst()) {
                dto.setSignInLimit("1");
                JsonResult signinResult = signinSchedule(dto);
                if (signinResult.getStatus().equals("1")) {
                    return JsonResultUtil.failure("预约成功后报到，失败原因：" + signinResult.getMessage());
                }
            }
        }
        return jsonResult;
    }

    @ApiOperation(value = "凭条打印", httpMethod = "POST", notes = "预约凭条打印")
    @PostMapping({"/print"})
    @LocalLock(key = "localLock:arg[0]")
    public JsonResult print(@RequestBody ExamApplyDto dto) {
        JsonResult jsonResult = examApplyService.print(dto);
        return jsonResult;
    }

    @ApiOperation(value = "多选凭条打印", httpMethod = "POST", notes = "多条预约凭条打印")
    @PostMapping({"/printMulti"})
    @LocalLock(key = "localLock:arg[0]")
    public JsonResult printMulti(@RequestBody List<ExamApplyDto> list) {
        JsonResult jsonResult = examApplyService.printMulti(list);
        return jsonResult;
    }

    @ApiOperation(value = "取消报道", httpMethod = "POST", notes = "取消报道状态")
    @PostMapping({"/sign/cancel"})
    @LocalLock(key = "localLock:arg[0]")
    public JsonResult delSign(@RequestBody ExamApplyDto dto) {

        return JsonResultUtil.failure("已报到不能取消!");

        //region -- 取消报到功能 todo：后期根据配置是否开放取消报到功能
        //        JsonResult jsonResult = examApplyService.delSign(dto);
//        if (jsonResult.getStatus().equals("0")) {
//            ExamApplyDto examApplyDto = new ExamApplyDto();
//            List<String> applyNos = CommonUtil.mergeNo2ApplyNos(dto.getMergeNo());
//            examApplyDto.setApplyNos(applyNos);
//            String actType = ConstantsUtil.ActType.CANCEL_SIGN.getType();
//            examApplyDto.setActType(actType);
//            ExamApplyDto applyResult = (ExamApplyDto) jsonResult.getResult();
//            examApplyDto.setExamClass(applyResult.getExamClass());
//            examApplyDto.setScheduledId(applyResult.getScheduledId());
//            examApplyDto.setMergeNo(applyResult.getMergeNo());
//            examApplyDto.setApplyNo(dto.getApplyNo());
//            examApplyDto.setTerminalType(applyResult.getTerminalType());
//            examApplyDto.setScheduleDate(applyResult.getScheduleDate());
//            examApplyDto.setName(applyResult.getName());
//            examApplyDto.setSex(applyResult.getSex());
//            examApplyDto.setAge(applyResult.getAge());
//            examApplyDto.setScheduleApm(applyResult.getScheduleApm());
//            examApplyDto.setScheduleHospitalName(applyResult.getScheduleHospitalName());
//            examApplyDto.setPerformDeptName(applyResult.getPerformDeptName());
//            String itemNameStr = "";
//            for (ExamApplyItemDto item : applyResult.getItems()) {
//                itemNameStr = itemNameStr + item.getItemName() + ";";
//            }
//            examApplyDto.setItemNameStr(itemNameStr);
//            configServiceImpl.isScheduleSync(examApplyDto, actType, ConstantsUtil.ScheduleStatus.ZEROZERO.getStatus());
//        }
//        return jsonResult;
        //endregion
    }

    /**
     * 患者是否怀孕 且 申请的检查项目有和孕期相关的限制
     *
     * @param dto
     * @return
     */
    @PostMapping({"/isGestation"})
    public JsonResult isGestation(@RequestBody ExamApplyDto dto) {
        return examApplyService.isGestation(dto);
    }

    /**
     * 修改怀孕周数
     *
     * @param dto
     * @return
     */
    @PostMapping({"/editLastMensesDate"})
    public JsonResult editLastMensesDate(@RequestBody ExamApplyDto dto) {
        return examApplyService.editLastMensesDate(dto);
    }

    @PostMapping({"/editExamApply"})
    @CheckOne({"applyNo", "mergeNo", "applyNos"})
    public JsonResult editExamApply(@RequestBody ExamApplyDto dto) {
        return examApplyService.editExamApply(dto);
    }

    /**
     * 预约退回
     *
     * @param dto
     * @return
     */
    @PostMapping({"/goBack"})
    public JsonResult goBack(@RequestBody ExamApplyDto dto) {
        return scheduleSignService.gotBack(dto);
    }

    @PostMapping({"/cancelExamApply"})
    public JsonResult cancelExamApply(@RequestBody ExamApplyDto dto) {
        return scheduleSignService.cancelExamApply(dto);
    }

    /**
     * 获取可预约队列列表
     *
     * @param dto
     * @return
     */
    @PostMapping({"/getScheduleQueues"})
    public JsonResult getScheduleQueues(@RequestBody ExamApplyDto dto) {
        return examApplyService.getScheduleQueues(dto);
    }

    /**
     * 获取可以预约的最早的日期和时段列表
     *
     * @param dto
     * @return
     */
    @PostMapping({"/date/first"})
    public JsonResult dateFirst(@RequestBody ExamApplyDto dto) {
        JsonResult jsonResult = scheduleSignService.getDateFirst(dto);
        return jsonResult;
    }

    /**
     * 检查预约时间是否冲突
     *
     * @param dto
     * @return
     */
    @PostMapping({"/conflict"})
    // @Check({"startTime", "endTime"})
    @CheckOne({"applyNo", "mergeNo"})
    public JsonResult conflict(@RequestBody ExamApplyDto dto) {
        if ("B".equals(dto.getTerminalType()) || "H".equals(dto.getTerminalType())) {
            return JsonResultUtil.success("成功");
        }
        return scheduleSignService.scheduleConflict(dto);
    }

    @PostMapping({"/editApplyFlag"})
    public JsonResult editApplyFlag(@RequestBody ExamApplyDto dto) {
        return examApplyService.editApplyFlag(dto);
    }

    @PostMapping({"/gestationalWeeks"})
    public JsonResult gestationalWeeks(@RequestBody ExamApplyDto dto) {
        int pregnantDays = DateUtil.getIntervalDays(dto.getLastMensesDate(), dto.getScheduleDate());
        int weeks = pregnantDays / 7;
        int days = pregnantDays % 7;
        String gestationalWeeks = weeks + "周";
        if (days > 0) {
            gestationalWeeks = gestationalWeeks + days + "天";
        }
        return JsonResultUtil.success("成功", gestationalWeeks);
    }

    /**
     * 获取员工
     *
     * @param dto
     * @return
     */
    @PostMapping({"/getStaffNames"})
    @Check({"hospitalCode", "examClass"})
    public JsonResult getStaffNames(@RequestBody DictScheduleApmDto dto) {
        dto.setClassAttr(null);
        return JsonResultUtil.success(dictScheduleApmService.getApmStaffName(dto));
    }

    @PostMapping({"/getWaitExamInfo"})
    @Check({"examNo"})
    public JsonResult getWaitExamInfo(@RequestBody ExamApplyDto dto) {
        return examApplyService.getWaitExamInfo(dto);
    }

    /**
     * 对某一条申请单进行快速预约操作
     *
     * @param dto
     * @return
     */
    @PostMapping({"/scheduleDatePlanMulti"})
    @Check({"planMode", "applyNo", "terminalType"})
    public JsonResult scheduleDatePlanMulti(@RequestBody ExamApplyDto dto) {
        // 解析申请单号列表
        dto.setApplyNos(CommonUtil.split2List(dto.getApplyNo()));
        List<ExamApply> applys = examApplyService.getList(dto);
        List<ExamApplyDto> applyDtos = new ArrayList<>();
        if (!CollectionUtils.isEmpty(applys)) {
            Map<String, List<String>> map = new HashMap<>();
            for (ExamApply apply : applys) {
                String sickId = apply.getSickId();
                String applyNo = apply.getApplyNo();
                if (!map.containsKey(sickId)) {
                    map.put(sickId, Arrays.asList(applyNo));
                } else {
                    ArrayList<String> list = new ArrayList<>(map.get(sickId));
                    list.add(applyNo);
                    map.put(sickId, list);
                }
            }
            for (String s : map.keySet()) {
                ExamApplyDto examApplyDto = new ExamApplyDto();
                examApplyDto.setPlanMode(dto.getPlanMode());
                examApplyDto.setTerminalType(dto.getTerminalType());
                examApplyDto.setApplyNo(StringUtils.join(map.get(s), ","));
                JsonResult jsonResult = examApplyPatientService.getPatientApplyList(examApplyDto);
                applyDtos.addAll((Collection<? extends ExamApplyDto>) jsonResult.getResult());
            }
        }
        return JsonResultUtil.success(applyDtos);
    }


    /***
     * 移动端获取预约提示内容
     * @param dto
     * @return
     */
    @PostMapping({"/mobile/getHint"})
    @Check({"applyNo"})
    public JsonResult getHint(@RequestBody ExamApplyDto dto) {
        return examApplyService.getHint(dto);
    }
}
